Make `Layout` a private implementation detail of toml
authorAleksey Kladov <aleksey.kladov@gmail.com>
Sun, 2 Jul 2017 08:01:25 +0000 (11:01 +0300)
committerAleksey Kladov <aleksey.kladov@gmail.com>
Sat, 8 Jul 2017 15:14:33 +0000 (18:14 +0300)
src/cargo/core/workspace.rs
src/cargo/ops/cargo_read_manifest.rs
src/cargo/ops/mod.rs
src/cargo/util/toml.rs

index 36df965eb2f9a0b58fc21ec16bfce0d472fd8d3b..a953f72c4d2a9db8eeb9b09238a67e515b4e2f0f 100644 (file)
@@ -7,10 +7,10 @@ use glob::glob;
 
 use core::{Package, VirtualManifest, EitherManifest, SourceId};
 use core::{PackageIdSpec, Dependency, Profile, Profiles};
-use ops;
 use util::{Config, Filesystem};
 use util::errors::{CargoResult, CargoResultExt};
 use util::paths;
+use util::toml::read_manifest;
 
 /// The core abstraction in Cargo for working with a workspace of crates.
 ///
@@ -594,9 +594,8 @@ impl<'cfg> Packages<'cfg> {
             Entry::Occupied(e) => Ok(e.into_mut()),
             Entry::Vacant(v) => {
                 let source_id = SourceId::for_path(key)?;
-                let pair = ops::read_manifest(&manifest_path, &source_id,
-                                              self.config)?;
-                let (manifest, _nested_paths) = pair;
+                let (manifest, _nested_paths) =
+                    read_manifest(&manifest_path, &source_id, self.config)?;
                 Ok(v.insert(match manifest {
                     EitherManifest::Real(manifest) => {
                         MaybePackage::Package(Package::new(manifest,
index 98cfde1d38974d7b9ad48bce5477542757db0ca4..0f93b3bfd68161610013cd6dad8cde97b51c540d 100644 (file)
@@ -4,23 +4,10 @@ use std::io;
 use std::path::{Path, PathBuf};
 
 use core::{Package, SourceId, PackageId, EitherManifest};
-use util::{self, paths, Config};
+use util::{self, Config};
 use util::errors::{CargoResult, CargoResultExt};
 use util::important_paths::find_project_manifest_exact;
-use util::toml::Layout;
-
-pub fn read_manifest(path: &Path, source_id: &SourceId, config: &Config)
-                     -> CargoResult<(EitherManifest, Vec<PathBuf>)> {
-    trace!("read_package; path={}; source-id={}", path.display(), source_id);
-    let contents = paths::read(path)?;
-
-    let layout = Layout::from_project_path(path.parent().unwrap());
-    let root = layout.root.clone();
-    util::toml::to_manifest(&contents, source_id, layout, config).chain_err(|| {
-        format!("failed to parse manifest at `{}`",
-                root.join("Cargo.toml").display())
-    })
-}
+use util::toml::read_manifest;
 
 pub fn read_package(path: &Path, source_id: &SourceId, config: &Config)
                     -> CargoResult<(Package, Vec<PathBuf>)> {
index 8d8908320134197b6df78d9016bb7ff408aea560..8440468efa4e7aca72c7ace73767cd2b5d2d8ba7 100644 (file)
@@ -1,7 +1,7 @@
 pub use self::cargo_clean::{clean, CleanOptions};
 pub use self::cargo_compile::{compile, compile_with_exec, compile_ws, CompileOptions};
 pub use self::cargo_compile::{CompileFilter, CompileMode, MessageFormat, Packages};
-pub use self::cargo_read_manifest::{read_manifest,read_package,read_packages};
+pub use self::cargo_read_manifest::{read_package, read_packages};
 pub use self::cargo_rustc::{compile_targets, Compilation, Kind, Unit};
 pub use self::cargo_rustc::{Context, is_bad_artifact_name};
 pub use self::cargo_rustc::{BuildOutput, BuildConfig, TargetConfig};
index bba874791d413e731a2b20a9ad15d1b7aa87ddb1..cb684fa02843c08727ffd3ac17f30e7779036129 100644 (file)
@@ -18,16 +18,13 @@ use core::dependency::{Kind, Platform};
 use core::manifest::{LibKind, Profile, ManifestMetadata};
 use ops::is_bad_artifact_name;
 use sources::CRATES_IO;
+use util::paths;
 use util::{self, ToUrl, Config};
 use util::errors::{CargoError, CargoResult, CargoResultExt};
 
-/// Representation of the projects file layout.
-///
-/// This structure is used to hold references to all project files that are relevant to cargo.
-
-#[derive(Clone)]
-pub struct Layout {
-    pub root: PathBuf,
+/// Implicit Cargo targets, defined by conventions.
+struct Layout {
+    root: PathBuf,
     lib: Option<PathBuf>,
     bins: Vec<PathBuf>,
     examples: Vec<PathBuf>,
@@ -38,7 +35,7 @@ pub struct Layout {
 impl Layout {
     /// Returns a new `Layout` for a given root path.
     /// The `root_path` represents the directory that contains the `Cargo.toml` file.
-    pub fn from_project_path(root_path: &Path) -> Layout {
+    fn from_project_path(root_path: &Path) -> Layout {
         let mut lib = None;
         let mut bins = vec![];
         let mut examples = vec![];
@@ -114,11 +111,24 @@ fn try_add_files(files: &mut Vec<PathBuf>, root: PathBuf) {
     /* else just don't add anything if the directory doesn't exist, etc. */
 }
 
-pub fn to_manifest(contents: &str,
-                   source_id: &SourceId,
-                   layout: Layout,
-                   config: &Config)
-                   -> CargoResult<(EitherManifest, Vec<PathBuf>)> {
+pub fn read_manifest(path: &Path, source_id: &SourceId, config: &Config)
+                     -> CargoResult<(EitherManifest, Vec<PathBuf>)> {
+    trace!("read_manifest; path={}; source-id={}", path.display(), source_id);
+    let contents = paths::read(path)?;
+
+    let layout = Layout::from_project_path(path.parent().unwrap());
+    let root = layout.root.clone();
+    to_manifest(&contents, source_id, layout, config).chain_err(|| {
+        format!("failed to parse manifest at `{}`",
+                root.join("Cargo.toml").display())
+    })
+}
+
+fn to_manifest(contents: &str,
+               source_id: &SourceId,
+               layout: Layout,
+               config: &Config)
+               -> CargoResult<(EitherManifest, Vec<PathBuf>)> {
     let manifest = layout.root.join("Cargo.toml");
     let manifest = match util::without_prefix(&manifest, config.cwd()) {
         Some(path) => path.to_path_buf(),